#include "helper.h"
#include "monitor.h"
#include "reg.h"
#include <stdio.h>

extern uint32_t instr;
extern char assembly[80];

/* decode J-type instrucion with unsigned immediate */
static void decode_jump_type(uint32_t instr) {

	op_src2->type = OP_TYPE_JUMP;
    op_src2->imm = (instr & INDEX_MASK);
    op_src2->val = op_src2->imm;


}
//get information of one demmand

make_helper(j){
    decode_jump_type(instr);

    uint32_t tmp = op_src2->val << 2;

    cpu.pc = ( ( (cpu.pc) & 0xf0000000) | tmp );

    sprintf(assembly , "j %08x" , cpu.pc);
    cpu.pc -= 4;
}

make_helper(jal){
    decode_jump_type(instr);
    
    cpu.gpr[31]._32 = cpu.pc + 4;

    uint32_t tmp = op_src2->val << 2;

    cpu.pc = ( ((cpu.pc) & 0xf0000000) | tmp );

    sprintf(assembly , "jal %08x" , cpu.pc);

    cpu.pc -= 4;
}